package com.wman.a28_lib_reflection;

import android.app.Activity;

import java.lang.reflect.Field;

/**
 * @ProjectName: wman
 * @Package: com.wman.a28_lib_reflection
 * @ClassName: Binding
 * @Description: java类作用描述
 * @Author: wman
 * @CreateDate: 2020/1/14 14:35
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/1/14 14:35
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class Binding {
    public static void bind(Activity activity) {
        for (Field field : activity.getClass().getDeclaredFields()) {
            BindView bindView = field.getAnnotation(BindView.class);
            if (bindView != null) {
                field.setAccessible(true);
                try {
                    field.set(activity, activity.findViewById(bindView.value()));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
